// 封装user的状态模块
import { getToken, setToken, removeToken } from '@/utils/storage'
const state = {
  // number: 100// 测试state挂载成功
  // tokenInfo: {}
  // tokenInfo: JSON.parse(localStorage.getItem('tokenInfo')) || {}
  tokenInfo: getToken() || {}
}
const mutations = {
  // 存储token的mutation
  setTokenInfo (state, newTokenInfo) {
    state.tokenInfo = newTokenInfo // 存储到仓库中
    // 存储在本地存储一份
    // localStorage.setItem('tokenInfo', JSON.stringify(newTokenInfo))
    setToken(newTokenInfo)
  },
  // 移除tokenInfo
  removeTokenInfo (state) {
    state.tokenInfo = {}
    removeToken()
  }
}
const actions = {}
const getters = {}
export default {
  namespaced: true, // 开启命名空间之后,mutations / actions / getters 不会挂载到全局了
  state,
  mutations,
  actions,
  getters
}
// 导出之后在store中挂载模块
